home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / orchestras / ReadFloatFile.c < prev    next >
Text File  |  1990-09-11  |  3KB  |  129 lines

  1. /* this instrument just reads in a sound file (of type FLOAT)
  2. (assumed to be mono) and outputs it as a stereo file.
  3.  
  4. */
  5. /*
  6. * ⌐ Graeme Gerrard 1990
  7. * Faculty of Music, University of Melbourne
  8. * Parkville Victoria 3052 Australia.
  9. *
  10. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  11. * telephone: (613) 344 4127, Fax: (613) 344 5104
  12. */
  13.  
  14.  
  15.  
  16. #define    READTYPE    1    /* type of instrument */
  17.  
  18. #include    <math.h>
  19. #include    "Music4c.h"
  20. #include    "ugens.h"
  21. #include    "orch.h"
  22. #include    "Music4C_Prototype.h"
  23.  
  24.  
  25. static    double E_buf[512];
  26. static    int    E_buflen;
  27. static    double    E_ptr;
  28. static    double    E_si;
  29. static    double    InSig;
  30. static    double    OutSig;
  31. static    ParmBlkPtr    E_myPBlkPtr;
  32. static    ParamBlockRec        E_myPBlk;
  33. static    long StartSamp, EndSamp;
  34. static    double SampPtr;
  35.  
  36. Boolean    SetSFDir(Str255, long *);
  37. extern    long    SoundFileDirID;
  38. extern    Str255    SFDirectoryName;
  39. extern    Str255    theMess1;
  40. extern    OSErr    theErr;
  41. extern    DialogPtr    thePass3DialogPtr;
  42. extern    void    DisplayDialog(DialogPtr);
  43.  
  44.  
  45.  
  46. void initl()
  47. {
  48.  
  49.     Point    where;
  50.     SFTypeList    types;
  51.     SFReply        theFileReply;
  52.     long        nBytes;
  53.  
  54.     E_buflen = 512;
  55.     E_myPBlkPtr = &E_myPBlk;
  56.     
  57.     /* set up soundfile directory*/
  58.     SetSFDir(SFDirectoryName, &SoundFileDirID);
  59.     
  60.     SetPt(&where, 100, 100);
  61.     types[0] = 'TEXT';
  62.     SFGetFile(where, NIL, NIL, 1, types, NIL, &theFileReply);
  63.     if(!theFileReply.good) {
  64.         FixUp();
  65.         CleanUp(FALSE);
  66.     }
  67.     DisplayDialog(thePass3DialogPtr);
  68.     E_myPBlkPtr->ioParam.ioNamePtr = (StringPtr)theFileReply.fName;
  69.     E_myPBlkPtr->ioParam.ioVRefNum = NIL;
  70.     E_myPBlkPtr->ioParam.ioVersNum = NIL;
  71.     E_myPBlkPtr->ioParam.ioPermssn = fsRdPerm;
  72.     theErr = PBOpen(E_myPBlkPtr, FALSE);
  73.     if ( theErr != noErr ) {
  74.         PstringCopy((char *)theMess1, "\pError opening file");
  75.         OSError(theMess1, theFileReply.fName, theErr);
  76.     }
  77.  
  78.     E_myPBlkPtr->ioParam.ioCompletion = NIL;
  79.     PBGetEOF(E_myPBlkPtr, FALSE);
  80.     nBytes = (long)E_myPBlkPtr->ioParam.ioMisc;
  81. }
  82.  
  83. void setup()
  84. {
  85.  
  86.     switch( instype ) {
  87.         case    READTYPE:
  88.  
  89.             E_si = p[4];                    /* sample increment */
  90.             SampPtr = p[5];        /* start sample in file */
  91.             StartSamp = (long)SampPtr;
  92.             if ( !SF_FLOAT_ReadSet( E_buf, E_buflen, &E_ptr, E_myPBlkPtr, &SampPtr, &StartSamp, &EndSamp) ) {
  93.                 fprintf(stderr,"bad file name?\n");
  94.             }
  95.             OutSig = 0.0;
  96.             InSig = 0.0;
  97.             break;
  98.         default:
  99.             fprintf(stderr, "Wrong file type\n");
  100.     }
  101.  
  102. }
  103.  
  104. void orch()
  105. {
  106.     switch( instype ) {
  107.         case    READTYPE:
  108.             InSig = SF_FLOAT_Read(E_myPBlkPtr, E_si, E_buf, E_buflen, &E_ptr, &SampPtr, &StartSamp, &EndSamp);
  109.             OutSig = InSig * 20000.0;
  110.             Stereo(OutSig, 0.5);
  111.             break;
  112.         default:
  113.             fprintf(stderr, "Wrong instrument type\n");
  114.     }
  115. }
  116. void    ter()
  117. {
  118. }
  119.  
  120.  
  121. void final()
  122. {
  123. /* called at the end of the synth run.
  124. *  close any files etc. you haven't already closed here.
  125. */
  126.     PBClose(E_myPBlkPtr, FALSE);
  127. }
  128.  
  129.